package com.bestv.search.common.service.impl;

import com.bestv.search.common.dao.InfoHeaderDao;
import com.bestv.search.common.dataSource.DataSourceKey;
import com.bestv.search.common.model.InfoHeader;
import com.bestv.search.common.service.InfoHeaderManager;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class InfoHeaderManagerImpl implements InfoHeaderManager {
    private InfoHeaderDao infoHeaderDao;

    @Override
    public List<InfoHeader> get(DataSourceKey key, String name, String p_type) {
        return infoHeaderDao.get(name, p_type);
    }

    @Override
    public InfoHeader get(DataSourceKey key, String code) {
        return infoHeaderDao.get(code);
    }

    @Override
    public InfoHeader get(DataSourceKey key, long id) {
        return infoHeaderDao.get(id);
    }

    @Override
    public List<InfoHeader> getAllValidHeader(DataSourceKey key) {
        return infoHeaderDao.getAllValidHeader();
    }

    @Override
    public List<InfoHeader> getInfoHeaderLikeName(DataSourceKey key, String name, String headerType, int start,
                                                  int limit) {
        return infoHeaderDao.getInfoHeaderLikeName(name, headerType, start, limit);
    }

    @Override
    public int getInfoHeaderCountLikeName(DataSourceKey key, String name, String headerType) {
        return infoHeaderDao.getInfoHeaderCountLikeName(name, headerType);
    }

    @Override
    public String getDefaultCodeByHeaderId(DataSourceKey key, long headerId) {
        return infoHeaderDao.getDefaultCodeByHeaderId(headerId);
    }

    @Override
    public int getTotalHitCountByHeaderId(DataSourceKey key, long headerId) {
        return infoHeaderDao.getTotalHitCountByHeaderId(headerId);
    }

    @Override
    public int getItemCountByHeaderId(DataSourceKey key, long headerId) {
        return infoHeaderDao.getItemCountByHeaderId(headerId);
    }

    @Override
    public void saveOrUpdate(DataSourceKey key, InfoHeader header) {
        if (header != null) {
            infoHeaderDao.saveOrUpdate(header);
        }
    }

    @Override
    public void saveOrUpdate(DataSourceKey key, List<InfoHeader> headers) {
        if (headers != null) {
            for (InfoHeader header : headers) {
                infoHeaderDao.saveOrUpdate(header);
            }
        }
    }

    @Override
    public boolean existOnlineInfosForHeaderId(DataSourceKey key, long headerId) {
        return infoHeaderDao.existOnlineInfosForHeaderId(headerId);
    }

    @Override
    public List<InfoHeader> getHeadersByUpdateTime(DataSourceKey key, Date updateTime) {
        return infoHeaderDao.getHeadersByUpdateTime(updateTime);
    }

    @Override
    public List<Map<String, String>> getInfoHeaderItemByHeaderId(DataSourceKey key, long headerId) {
        return infoHeaderDao.getInfoHeaderItemByHeaderId(headerId);
    }

    public InfoHeaderDao getInfoHeaderDao() {
        return infoHeaderDao;
    }

    public void setInfoHeaderDao(InfoHeaderDao infoHeaderDao) {
        this.infoHeaderDao = infoHeaderDao;
    }
}